//
//  FDMPushListenNewsCollectionViewCell.m
//  Entertainment
//
//  Created by dllo on 16/4/20.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMPushListenNewsCollectionViewCell.h"
#import "FDMPushFindNewsModel.h"

@interface FDMPushListenNewsCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imageView;/**< 发现新奇的图片 */

@property (nonatomic, retain) UILabel *titleLabel;/**< 发现新奇的标题 */

@end
@implementation FDMPushListenNewsCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView];
        [self.imageView release];
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel release];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

- (void)dealloc {
    [self.imageView release];
    [self.titleLabel release];
    [self.model release];
    [super dealloc];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-20);
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(-10);
        
    }];
}

- (void)setModel:(FDMPushFindNewsModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        self.titleLabel.text = _model.title;
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:_model.coverPath] placeholderImage:PLACEHOLDER_IMAGE];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
